<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
	<title>Insert title here</title>
  	<script type="text/javascript" src="js/jquery-3.2.1.min.js" ></script>
</head>
<body>
<!-- 	<form action="/cm/user/add" method="POST">
		<input name="username" placeholder="username" value="Q1" />
		<input name="password" placeholder="password" value="7754" />
		<input type="submit" value="添加" />
	</form> -->
	<br />
	<form action="/login" method="POST" id="loginForm">
		<input name="username" placeholder="username" value="Q1" />
		<input name="password" placeholder="password" value="7754" />
		<label>记住我: <input name="remember-me" type="checkbox" onclick="rem_me(this)"/></label>
	</form>
		<input type="submit" onclick="clickLoginBt()" value="登录" />
	
	<br />	
	<form action="/register" method="POST" id="registerForm">
		<input name="username" placeholder="username" value="Q2" />
		<input name="password" placeholder="password" value="7754" />
	</form>
		<input type="submit" onclick="clickRegisterBt()" value="注册" />
	
	<br />
	<a href="/cm/per.html" target="_blank">per</a> | 
	<!-- <a href="/logout" target="_blank">注销</a> -->
	<input type="submit" onclick="logout()" value="注销"/>
	<input type="submit" onclick="re()" value="re"/>
         <script>
         function rem_me(el){
        	 var e = $(el);
        	 console.log(e.prop('checked'));
        	 console.log(el.checked);
         }
         
         
         function clickLoginBt(){
           var formdata = $("#loginForm").serialize()
           
           var jsondata = {
        		   "username": $("#loginForm input[name='username']").val(),
        		   "password": $("#loginForm input[name='password']").val(),
        		   "remember-me": $("#loginForm input[name='remember-me']").prop('checked')
        	   };
           
           console.log(jsondata);
           
           $.ajax({
        	   type: "POST",
        	   url: "/cm/login",
        	   contentType: "application/json;charset-UTF-8",
        	   dataType: "json",
        	   data: JSON.stringify(jsondata),
        	   success: function(re){
        		   console.log(re);
        	   },
        	   error: function(re){
        		   console.log(re);
        	   }
           })
	     }
         

         function clickRegisterBt(){
             var jsondata = $("#registerForm").serialize()
             $.ajax({
          	   type: "POST",
          	   url: "/cm/register",
          	   contentType: "application/json;charset-UTF-8",
          	   dataType: "json",
          	   data: JSON.stringify({
        		   username: $("#registerForm input[name='username']").val(),
        		   password: $("#registerForm input[name='password']").val()
          	   }),
          	   success: function(re){
          		   console.log(re);
          	   },
          	   error: function(re){
          		   console.log(re);
          	   }
             })
  	     }
         
         function logout(){
             $.ajax({
          	   type: "POST",
          	   url: "/cm/logout",
          	   dataType: "json",
          	   success: function(re){
          		   console.log(re);
          	   },
          	   error: function(re){
          		   console.log(re);
          	   }
             })
  	     }
         
         function re(){
             var jsondata = $("#loginForm").serialize()
             var jd = {
            		 username: $("#loginForm input[name='username']").val(),
              		 password: $("#loginForm input[name='password']").val()
              	   };
             
             jsondata = jd;
             console.log(jsondata);
             
             $.ajax({
          	   type: "POST",
          	   url: "/cm/re",
           	   contentType: "application/json;charset-UTF-8",
          	   dataType: "json",
          	   data: JSON.stringify(jsondata), 
          	   //data: jsondata, 
          	   success: function(re){
          		   console.log(re);
          	   },
          	   error: function(re){
          		   console.log(re);
          	   }
             })
  	     }
           
         </script>
</body>
</html>